Editing a Geometry Object

This example demonstrates how to modify each part of a multipart geometry. This example uses the IGeometryCreator (CreateGeometryFromWKT), ICreator81 (CreatePolygon, IPosition81 (Distance, Pitch), INavigate81 (JumpTo), and IPolygon(StartEdit, EndEdit) properties and methods.

 

function EditPolygon()

      {

      try

      {

      var geometry = sgworld.Creator.GeometryCreator.CreateGeometryFromWKT("POLYGON((-82.900091 26.739261,-82.906338 26.840896,-82.591731 26.951601,-82.819248 26.717179,-82.900091 26.739261),(-82.873569 26.819371,-82.81616 26.772908,-82.811242 26.846308,-82.873569 26.819371))");

      var polygon = sgworld.Creator.CreatePolygon(geometry, "#00ff00", "#00ffff",0 /* AltitudeTypeCode.ATC_TERRAIN_RELATIVE */, "", "Polygon");

      polygon.Position.Distance = 81000;

      polygon.Position.Pitch = -45;

      sgworld.Navigate.JumpTo(polygon);

      alert("Polygon created. Click Ok to move all its points 0.001 to the right on x axis and add z value");

      var polygonGeometry = polygon.Geometry;

      // call start edit on the polygon

      polygonGeometry.StartEdit();

      // iterate over all of its rings. First one is exterior ring. All after it, are interior rings

      for (var ringIndex = 0; ringIndex < polygonGeometry.Rings.Count; ringIndex++)

                {

                    varring = polygonGeometry.Rings(ringIndex);

                    for(var pointIndex = 0; pointIndex < ring.Points.Count; pointIndex++)

                    {

                        varpoint = ring.Points(pointIndex);

                        point.X += 0.001;

                        point.Z += point.X + point.Y;

                    }

                }

                // call EndEdit at the end. EndEdit returns new IGeometry. It does so, because IPolygon could have turned to IMultiPolygon

                var editedGeometry = polygonGeometry.EndEdit();

                // set the new geometry to the object

                polygon.Geometry = editedGeometry;

            }

            catch (e)

            {

                alert("Unexpected error:" + e.description);

            }

        }